package chapter3.lc3;

public class LengthOfLongestSubstring2 {
    public int lengthOfLongestSubstring(String s) {
        int[] map = new int[128];
        int l = 0, r = 0;
        int len = 0;
        while (r < s.length()) {
            if (map[s.charAt(r)] == 0){
                map[s.charAt(r++)]++;
                len = Math.max(len, r-l);
            }else {
                map[s.charAt(l++)]--;
            }
        }
        return len;
    }
}
